package com.itheima.service.impl;

import com.itheima.domain.JobOption;
import com.itheima.mapper.EmpMapper;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@Slf4j
public class ReportServiceImpl implements ReportService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public JobOption empJobData() {
        List<Map<String, Object>> jobData = empMapper.empJobData();
        log.info("员工职位统计:{}", jobData);
        //利用stream流处理数据,提取集合中每个map的职位名称和职位数量
        List<Object> jobList = jobData.stream().map(m -> m.get("pos")).collect(Collectors.toList());
        List<Object> dataList = jobData.stream().map(m -> m.get("total")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> empGenderData() {
        return empMapper.empGenderData();
    }
}
